import request from "@/utils/request";

/**
 * 获取好友列表
 * @param params
 * @returns
 */
export function getFriendList(params?: any) {
  return request({
    url: "/social/friends",
    method: "get",
    params,
  });
}

/**
 * 获取好友请求列表
 * @param params
 * @returns
 */
export function getFriendRequests(params?: any) {
  return request({
    url: "/social/friend-requests",
    method: "get",
    params,
  });
}

/**
 * 发送好友请求
 * @param data
 * @returns
 */
export function sendFriendRequest(data: { userId: number | string }) {
  return request({
    url: "/social/friend-requests",
    method: "post",
    data,
  });
}

/**
 * 接受好友请求
 * @param requestId
 * @returns
 */
export function acceptFriendRequest(requestId: number | string) {
  return request({
    url: `/social/friend-requests/${requestId}/accept`,
    method: "post",
  });
}

/**
 * 拒绝好友请求
 * @param requestId
 * @returns
 */
export function rejectFriendRequest(requestId: number | string) {
  return request({
    url: `/social/friend-requests/${requestId}/reject`,
    method: "post",
  });
}

/**
 * 删除好友
 * @param friendId
 * @returns
 */
export function deleteFriend(friendId: number | string) {
  return request({
    url: `/social/friends/${friendId}`,
    method: "delete",
  });
}

/**
 * 获取聊天记录
 * @param params
 * @returns
 */
export function getChatMessages(friendId: number | string, params?: any) {
  return request({
    url: `/social/messages/${friendId}`,
    method: "get",
    params,
  });
}

/**
 * 发送消息
 * @param data
 * @returns
 */
export function sendMessage(data: { receiverId: number | string; content: string; type?: string }) {
  return request({
    url: "/social/messages",
    method: "post",
    data,
  });
}

/**
 * 获取未读消息数量
 * @returns
 */
export function getUnreadCount() {
  return request({
    url: "/social/messages/unread-count",
    method: "get",
  });
}

/**
 * 标记消息为已读
 * @param messageIds
 * @returns
 */
export function markMessagesAsRead(messageIds: (number | string)[]) {
  return request({
    url: "/social/messages/read",
    method: "post",
    data: { messageIds },
  });
}
